TK!2
=v
#1
:n
L
:v
1000
:s
i
:u
ft
:d
ft
:c
length of pipeline
#2
:n
Q
:v
20
:s
i
:u
gpm
:d
gpm
:c
fluid rate
#3
:n
D
:v
1.11726318496609
:s
o
:u
in
:d
in
:c
pipe diameter
#4
:n
cost
:v
1003.00058667407
:s
o
:c
annual cost of pipe, pump and pumping
=u
=l
#1
:n
D_2nd
:d
in
:u
in
:v
.25
.287044475701847
.329578124123792
.378414319367648
.43448695960383
.498868326075083
.572789588409921
.657664348370408
.755115672263122
.867007128956061
.9954784270438231
1.14298633265317
1.31235165036323
1.50681316565986
1.7300895804699
1.98645062617284
2.28079871398955
2.6187626841543
3.00680544664253
3.45234757187584
3.96390919483858
4.55127294624867
5.22567102652779
6
E
#2
:n
cost_2nd
:v
21205.4373495424
12595.8937891136
7728.88473512323
4934.24895009567
3302.63727668545
2334.56548145275
1752.77070836336
1401.48029361543
1192.06099357184
1073.50742622561
1016.29662149917
1003.48090026427
1025.73468169597
1078.58724777611
1160.88510705895
1273.96413909939
1421.24817681271
1608.12016109254
1841.98410303459
2132.47737898075
2491.81767143739
2935.28494083424
3481.85048114449
4154.97484179372
E
=f
#1
:n
piping
:c
Objective function example
:t
Rule
:p
L,Q
:a
D
:v
cost
#2
:n
Golden
:c
Golden section search (one-variable minimization)
:t
Procedure
:i
xa,xb,Fun
:o
x,F
#1
:n
piping
:z
cost = .45*L + .245*L*D^1.5 + 325*sqrt(hp) + 61.6*hp^.925 + 102
hp = L * (4.4e-8*Q^3/D^5 + 1.92e-9*Q^2.68/D^4.68)
/E
E
#2
:n
Golden
:z
" Notation:  xa,xb  search interval,  xa < xb
"            Fun    name of the objective function
"            x      value of abscissa making the objective function a
"                   minimum
"            F      minimum value of objective function

" Description: Single-variable minimization by golden section search method.
" It handles unconstrained optimization and also constrained optimization
" when the constraint is built into objective function as penalty.  There
" is no counter or limit of iteration steps.

tau:= .381966           " golden section ratio
Fa:= apply(Fun,xa)
Fb:= apply(Fun,xb)
x1:= xa + tau*(xb-xa)
F1:= apply(Fun,x1)
x2:= xb + tau*(xa-xb)
F2:= apply(Fun,x2)
loop:
  if or((xb-xa)<1e-12,(1-xa/xb)<1e-6) return
  if F1<F2 goto other
  (xa,x1):= (x1,x2)
  (Fa,F1):= (F1,F2)
  x2:= xb + tau*(xa-xb)
  F2:= apply(Fun,x2)
  (x,F):= (x2,F2)
  goto loop
other:
  (xb,x2):= (x2,x1)
  (Fb,F2):= (F2,F1)
  x1:= xa + tau*(xb-xa)
  F1:= apply(Fun,x1)
  (x,F):= (x1,F1)
  goto loop
/E
E
=r
#1
:r
"  ***  Single-variable Optimization, Part 3: Golden Section Search  ***
:s
C
#3
:r
call Golden(.25,6,'piping;D,cost)
#5
:r
" Notes:
:s
C
#6
:r
" 1. The problem deals with the design of a pipeline for a chemical plant
:s
C
#7
:r
"    satisfying the condition of minimum annual cost of pipe, pump and 
:s
C
#8
:r
"    pumping (see the description in model OPTIM1A and alternative methods
:s
C
#9
:r
"    of solution in models OPTIM1A, OPTIM1B and OPTIM1D).  The objective
:s
C
#10
:r
"    function is defined in the rule function  cost .
:s
C
#11
:r
" 2. The function  Golden  returns the optimum diameter  D  and minimum value
:s
C
#12
:r
"    of  cost  found by golden section search in the interval  .25 ó D ó 6
:s
C
#13
:r
"    (see the Function Subsheet).
:s
C
#14
:r
" 3. The interval was chosen in order to include the minimum point (press F7
:s
C
#15
:r
"    to see the graph of the objective function).  If such an interval is not
:s
C
#16
:r
"    known in advance, the function 'bracket' from model OPTIM1D may be used
:s
C
#17
:r
"    to find it.
:s
C
=p
#1
:n
second
:t
Line chart
:d
EGA
:i
""
:s
Yes
:z
None
:g
No
:l
None
:h
"Pipe Diameter"
:v
"Cost"
:x
D_2nd
:u
#1
:y
cost_2nd
:f
1
:p
Lines
:c
"*"
E
=t
#1
:n
trace
:s
Screen
:v
Vertical
:f
1
:r
""
:c
""
:t
""
:u
#1
:l
D
:w
20
:h
""
#2
:l
cost
:w
20
:h
""
E
=n
=g
#1
:c
.000001
:i
10
:v
Yes
:l
60
:f
66
:m
0
:w
80
:b
Yes
:a
Yes
:r
Yes
:h
No
:t
1
:n
Yes
:d
LPT1
%Tr,f,0,1,0,1,0
